//
//  DYColorView.m
//  colorTest
//
//  Created by 丁益 on 2017/4/9.
//  Copyright © 2017年 celi. All rights reserved.
//  显示当前颜色标签

#import "DYColorView.h"

@interface DYColorView()
@property (nonatomic, weak) UILabel *redValueLabel;
@property (nonatomic,weak) UILabel *greenValueLabel;
@property (nonatomic,weak) UILabel *blueValueLabel;

@end

@implementation DYColorView



+ (instancetype)colorViewWithFream:(CGRect)frame RedValue:(NSString*)redValue blueValue:(NSString *)blueValue greenValue:(NSString *)greenValue addTarget:(nullable id)target action:(SEL)action
{
    
    DYColorView *colorView = [[DYColorView alloc]initWithFrame:frame];
    CGFloat labelHeight = frame.size.height/3;
    CGFloat labelWidht = frame.size.width;
    
    UIButton *redLabel = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, labelWidht, labelHeight)];
    [redLabel addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *redLabelTitel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0,15, labelHeight)];
    redLabelTitel.text = @"R";
    redLabelTitel.textColor = [UIColor whiteColor];
    redLabelTitel.backgroundColor = [UIColor colorWithRed:88/255.0 green:88/255.0 blue:88/255.0 alpha:0.8];
    redLabel.backgroundColor = [UIColor redColor];
    [colorView addSubview:redLabel];
    [colorView addSubview:redLabelTitel];
    CGFloat redValueX = CGRectGetMaxX(redLabelTitel.frame);
    UILabel *redValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(redValueX,0,labelWidht-15, labelHeight)];
    redValueLabel.text = redValue;
    redValueLabel.textColor = [UIColor whiteColor];
    [redValueLabel setFont:[UIFont systemFontOfSize:14]];
    [colorView addSubview:redValueLabel];
    colorView.redValueLabel = redValueLabel;
    
    
    CGFloat greenLabelY = CGRectGetMaxY(redLabel.frame);
    UIButton *greenLabel = [[UIButton alloc]initWithFrame:CGRectMake(0,greenLabelY, labelWidht, labelHeight)];
    [greenLabel addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    greenLabel.backgroundColor = [UIColor greenColor];
    [colorView addSubview:greenLabel];
    UILabel *greenLabelTitel = [[UILabel alloc] initWithFrame:CGRectMake(0,greenLabelY,15, labelHeight)];
    greenLabelTitel.text = @"G";
    greenLabelTitel.textColor = [UIColor whiteColor];
    greenLabelTitel.backgroundColor = [UIColor colorWithRed:88/255.0 green:88/255.0 blue:88/255.0 alpha:0.8];
    [colorView addSubview:greenLabelTitel];
    UILabel *greenValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(redValueX,greenLabelY,labelWidht-15, labelHeight)];
    greenValueLabel.text = greenValue;
    greenValueLabel.textColor = [UIColor whiteColor];
    [greenValueLabel setFont:[UIFont systemFontOfSize:14]];
    [colorView addSubview:greenValueLabel];
    colorView.greenValueLabel = greenValueLabel;

    CGFloat blueLabelY = CGRectGetMaxY(greenLabel.frame);
    UIButton *blueLabel = [[UIButton alloc]initWithFrame:CGRectMake(0,blueLabelY, labelWidht, labelHeight)];
    [blueLabel addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    blueLabel.backgroundColor = [UIColor blueColor];
    [colorView addSubview:blueLabel];
    UILabel *blueLabelTitel = [[UILabel alloc] initWithFrame:CGRectMake(0,blueLabelY,15, labelHeight)];
    blueLabelTitel.text = @"B";
    blueLabelTitel.textColor = [UIColor whiteColor];
    blueLabelTitel.backgroundColor = [UIColor colorWithRed:88/255.0 green:88/255.0 blue:88/255.0 alpha:0.8];
    [colorView addSubview:blueLabelTitel];
    UILabel *blueValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(redValueX,blueLabelY,labelWidht-15, labelHeight)];
    blueValueLabel.text = blueValue;
    blueValueLabel.textColor = [UIColor whiteColor];
    [blueValueLabel setFont:[UIFont systemFontOfSize:14]];
    [colorView addSubview:blueValueLabel];
    colorView.blueValueLabel = blueValueLabel;
    return colorView;
}

- (void)setRedValue:(NSString *)redValue greenValue:(NSString *)greenValue blueValue:(NSString *)blueVaule
{
    self.greenValueLabel.text = greenValue;
    self.redValueLabel.text = redValue;
    self.blueValueLabel.text = blueVaule;
}




@end
